package mi.payment.utils.transaction;

import android.content.Context;

import java.util.Map;

import mi.payment.constants.TransactionBitmap;
import mi.payment.utils.iso8583.EncodePackage;
import mi.payment.utils.iso8583.MsgField;
import mi.payment.utils.secure.TerminalSecure;

/**
 * IC 卡公钥/参数/TMS 参数/卡 BIN 黑名单下载结束
 *
 * @author tomcat on 2017/2/17.
 */

public class DownloadFinishedTask extends TransactionTask<String, Void, String> {

    public DownloadFinishedTask(Context c) {
        super(c, false);
    }

    @Override
    protected void onBegin(String[] params) {
    }

    @Override
    protected String appointResult() {
        return resultStr;
    }

    @Override
    protected Map<String, MsgField> preAssembly() {
        return EncodePackage.preAssemblyBase(TransactionBitmap.BITMAP_DOWNLOAD_FINISH);
    }

    @Override
    protected byte[] changeAndAssembly(Map<String, MsgField> fieldMap) {
        String value60_3 = params[0]; // 网络管理信息码
        String msgType = params[1];   // 消息类型

        // 修改本交易的动态参数
        MsgField f041 = fieldMap.get("F041");
        f041.setDataStr(merManagerSettings.getTerminalNum());

        MsgField f042 = fieldMap.get("F042");
        f042.setDataStr(merManagerSettings.getMerchantNum());

        MsgField f060 = fieldMap.get("F060");
        f060.setDataStr("00" + mSystemParamsSettings.getBatchNumStart() + value60_3);
        f060.setDataLength(11);

        return EncodePackage.assembly(fieldMap, msgType, TerminalSecure.PROCESSREQUEST_NONE);
    }


}
